﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ChineseSchool.Models.Hethong;
using ChineseSchool.BLL;

namespace ChineseSchool.UserControl
{
    public partial class Banner : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lblBanner.Text = LoadBanner();
            }
        }

        public string LoadBanner()
        {
            string strImage = "";
            M_Image Image = new M_Image();
            List<M_Image> lstImage = new List<M_Image> { };
            if (Request.QueryString["id"] != null && Request.QueryString["id"] != "")
            {
                int MenuID = int.Parse(Request.QueryString["id"]);
                List<M_Page> lstPage = new List<M_Page> { };
                lstPage = (new B_Page()).GetBy_MenuID(MenuID);
                int PageID = 0;
                if (lstPage.Count > 0)
                {
                    PageID = lstPage[0].pageID;
                }
                lstImage = (new B_Image()).GetBy_PageID(PageID);
                if (lstImage != null && lstImage.Count > 0)
                {
                    strImage += "<ul class=\"items\">";
                    for (int i = 0; i < lstImage.Count; i++)
                    {
                        strImage += "<li><img src=\"" + lstImage[i].imageUrl.ToString() + "\" alt=\"\" />";
                        strImage += "<div class=\"banner\"><span>" + lstImage[i].imageName.ToString() + "</span>";
                        strImage += "<strong>" + lstImage[i].description.ToString() + " ";
                        strImage += "<a href=\"" + lstImage[i].link.ToString() + "\">Chi tiết</a></strong></div></li>";
                    }
                    strImage += "</ul>";
                }
                else
                {
                    lstImage = (new B_Image()).GetBy_PageID(0);
                    if (lstImage != null && lstImage.Count > 0)
                    {
                        strImage += "<ul class=\"items\">";
                        for (int i = 0; i < lstImage.Count; i++)
                        {
                            strImage += "<li><img src=\"" + lstImage[i].imageUrl.ToString() + "\" alt=\"\" />";
                            strImage += "<div class=\"banner\"><span>" + lstImage[i].imageName.ToString() + "</span>";
                            strImage += "<strong>" + lstImage[i].description.ToString() + " ";
                            strImage += "<a href=\"" + lstImage[i].link.ToString() + "\">Chi tiết</a></strong></div></li>";
                        }
                        strImage += "</ul>";
                    }
                }
            }
            else
            {
                lstImage = (new B_Image()).GetBy_PageID(0);
                if (lstImage != null && lstImage.Count > 0)
                {
                    strImage += "<ul class=\"items\">";
                    for (int i = 0; i < lstImage.Count; i++)
                    {
                        strImage += "<li><img src=\"" + lstImage[i].imageUrl.ToString() + "\" alt=\"\" />";
                        strImage += "<div class=\"banner\"><span>" + lstImage[i].imageName.ToString() + "</span>";
                        strImage += "<strong>" + lstImage[i].description.ToString() + " ";
                        strImage += "<a href=\"" + lstImage[i].link.ToString() + "\">Chi tiết</a></strong></div></li>";
                    }
                    strImage += "</ul>";
                }
            }
            return strImage;
        }
    }
}